package com.yx.cloud.product.laser.yxcloud;

import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.iot.base.bean.Device;
import com.iot.common.utils.LogUtils;
import com.iot.common.utils.ToastUtil;
import com.iot.product.sweeper.bean.Robot;
import com.iot.product.sweeper.bean.RobotStatus;
import com.iot.sweeper.AppContext;
import com.yx.cloud.MyApplication;
import com.yx.cloud.R;
import com.yx.cloud.bean.RobotIconColorBean;
import com.yx.cloud.product.ProductConfigConstants;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

public class U3FULLConfig {
    public static void initConfig(JSONObject configureMap, Device device) {
        try {
            configureMap.put(ProductConfigConstants.productId, U3_FULL.PID);

            configureMap.put(ProductConfigConstants.net_configure_type_ap, true); //AP配网 (机器创建wifi等待机器连接)
            configureMap.put(ProductConfigConstants.net_configure_type_ble, true);//蓝牙配网
            configureMap.put(ProductConfigConstants.net_configure_type_lan, false);//局域网配网（局域网发广播）
            configureMap.put(ProductConfigConstants.net_configure_type_wifi_p2p, false);//使用WIFI p2p通道

            configureMap.put(ProductConfigConstants.productName, "U3 Full");     //产品名称
            configureMap.put(ProductConfigConstants.productGuide, "U3 Pro");
            configureMap.put(ProductConfigConstants.default_robotName, R.string.U_DefaultDeviceName_Flower);
            configureMap.put(ProductConfigConstants.product_type, ProductConfigConstants.PRODUCT_TYPE_LASER);
            configureMap.put(ProductConfigConstants.product_desc, R.string.N_SweepAndMopRobot);
            configureMap.put(ProductConfigConstants.isInxni, false);
            configureMap.put(ProductConfigConstants.uploadLog, true);//上传日志

            configureMap.put(ProductConfigConstants.hasMap, true);//有无地图  陀螺仪rs01/x1/gd01没有地图  rs11有地图 激光有地图
            configureMap.put(ProductConfigConstants.hasMultiMap, true);//有无多楼层地图  陀螺仪没有
            configureMap.put(ProductConfigConstants.x5BaseStationHasMultiStyle, false); //X5基站扫地机图片是否可以切换风格
            configureMap.put(ProductConfigConstants.minCleanAreaSize, 0.5f);
            configureMap.put(ProductConfigConstants.powerProtectAreaSize, 0.5f);
            configureMap.put(ProductConfigConstants.minForbiddenAreaSize, 0.5f);
            configureMap.put(ProductConfigConstants.canRotateCleanArea, false);
            configureMap.put(ProductConfigConstants.isEditMapNeedPauseRecharge, true);
            configureMap.put(ProductConfigConstants.isEditCustomNeedPause, true);
            configureMap.put(ProductConfigConstants.custom_suction, true);     //是否可定制吸力
            configureMap.put(ProductConfigConstants.custom_water, true);     //是否可定制水量
            configureMap.put(ProductConfigConstants.custom_cleanTimes, false);     //是否可定制清扫次数
            configureMap.put(ProductConfigConstants.create_map_quickly, false);//地图界面创建地图按钮
            configureMap.put(ProductConfigConstants.furniture_edit, false);//家具编辑按钮
            configureMap.put(ProductConfigConstants.ddd_2_dd, false);            //3d 2d 切换按钮
            configureMap.put(ProductConfigConstants.rotate_map, false);            //地图旋转按钮
            configureMap.put(ProductConfigConstants.reset_room, false);            //恢复默认分区

            //预约
            configureMap.put(ProductConfigConstants.alarmCleanType, true);
            configureMap.put(ProductConfigConstants.alarmMopWater, true); //pd和陀螺仪没有水量
            configureMap.put(ProductConfigConstants.alarmSuction, true);
            configureMap.put(ProductConfigConstants.maxAlarmCount, 10);


            configureMap.put(ProductConfigConstants.hasDustCollectingBarrel, true);
            configureMap.put(ProductConfigConstants.hasConsumablesMaintain, true);
            configureMap.put(ProductConfigConstants.hasMopDry, true);
            configureMap.put(ProductConfigConstants.hasFirmwareAutoUpdate, true);
            configureMap.put(ProductConfigConstants.customerService, true);

            configureMap.put(ProductConfigConstants.robotIconId, R.mipmap.robot_icon_u3pro);
            configureMap.put(ProductConfigConstants.robot_Airview, R.mipmap.main_u3pro_icon);
            configureMap.put(ProductConfigConstants.robot_Preview, R.mipmap.equipment_icon_pic_u3pro);
            configureMap.put(ProductConfigConstants.robot_Virtual, R.mipmap.robot_icon_x3);
            configureMap.put(ProductConfigConstants.robot_airview_default, R.mipmap.robot_icon_u3pro);//main_x3_white_icon
            configureMap.put(ProductConfigConstants.robot_transparent_icon, R.mipmap.robot_transparent_icon_x3);

            JSONArray jsonArray = new JSONArray();
            jsonArray.put(R.drawable.u3pro_white_light);
            jsonArray.put(R.drawable.u3pro_pink_light);
            jsonArray.put(R.drawable.u3pro_red_light);
            configureMap.put(ProductConfigConstants.robot_light_images, jsonArray);
            configureMap.put(ProductConfigConstants.hasMultiStyle, false);
            configureMap.put(ProductConfigConstants.rightSideBrush, true);
            configureMap.put(ProductConfigConstants.robot_home_env_2, R.mipmap.connects_success_item2);


            configureMap.put(ProductConfigConstants.cleanSetting_chooseRoom, true);
            configureMap.put(ProductConfigConstants.cleanSetting_spotClean, false);
            configureMap.put(ProductConfigConstants.cleanSetting_edgeClean, false);
            configureMap.put(ProductConfigConstants.cleanSetting_quickClean, false);
            configureMap.put(ProductConfigConstants.cleanSetting_customMode, true);
            configureMap.put(ProductConfigConstants.cleanSetting_sterilizeMode, false);
            configureMap.put(ProductConfigConstants.cleanSetting_fineRub, false);
            configureMap.put(ProductConfigConstants.cleanSetting_noneSuction, false);
            configureMap.put(ProductConfigConstants.cleanSetting_selfCleaningFrequency, false);
            configureMap.put(ProductConfigConstants.cleanSetting_carpetPressurization, true);
            configureMap.put(ProductConfigConstants.cleanSetting_hasDryMop, false);
            configureMap.put(ProductConfigConstants.cleanSetting_mopWater, true);
            configureMap.put(ProductConfigConstants.cleanSetting_suction, true);
            configureMap.put(ProductConfigConstants.cleanSetting_isConbineWaterTankAndDustBox, false);
            configureMap.put(ProductConfigConstants.moppingTwoGears, false);
            configureMap.put(ProductConfigConstants.robotSetting_volume, true);
            configureMap.put(ProductConfigConstants.robotSetting_break_continue, true);
            configureMap.put(ProductConfigConstants.robotSetting_no_disturb, true);
            configureMap.put(ProductConfigConstants.robotSetting_silent, false);
            configureMap.put(ProductConfigConstants.robotSetting_factoryset, false);
            configureMap.put(ProductConfigConstants.robotSetting_light, true);
            configureMap.put(ProductConfigConstants.carpetSetting_suction, true);//ZW2X 清扫模式/地毯设置/
            configureMap.put(ProductConfigConstants.dust_collection_frequency, false);//集尘频率
            configureMap.put(ProductConfigConstants.showCleanTime, true);
            configureMap.put(ProductConfigConstants.showCleanArea, true);
            configureMap.put(ProductConfigConstants.cleanSetting_OnlySuctionShown, false);
            configureMap.put(ProductConfigConstants.cleanSetting_Max_Suction_show, true);//吸力 超强档位
            configureMap.put(ProductConfigConstants.alarmCleaningFrequency, false);//清洗次数
            //耗材 寿命 单位(s)    值为-1 表示这个产品无此耗材
            configureMap.put(ProductConfigConstants.consumable_dustStrainer, 150 * 3600);//尘盒滤网
            configureMap.put(ProductConfigConstants.consumable_sideBrush, 200 * 3600);//边刷
            configureMap.put(ProductConfigConstants.consumable_mainBrush, 300 * 3600);//主刷
            configureMap.put(ProductConfigConstants.consumable_mop, 150 * 3600);//拖布
            configureMap.put(ProductConfigConstants.consumable_laserSensor, -1);//激光传感器
            configureMap.put(ProductConfigConstants.consumable_dustBag, -1);//集尘桶 尘袋
            configureMap.put(ProductConfigConstants.consumable_waterStrainer, -1);//扫拖模块滤网
            configureMap.put(ProductConfigConstants.backStopControl, false);
            configureMap.put(ProductConfigConstants.rechargeStopControl, true);
            configureMap.put(ProductConfigConstants.spotCleanStopControl, false);
            configureMap.put(ProductConfigConstants.canUpgradeFirmware, canUpgradeFirmware());
            configureMap.put(ProductConfigConstants.firmwareUpgradeFail, false);//固件更新失败后弹框提示
            configureMap.put(ProductConfigConstants.canUpgradeFirmwareChannel, false);

            //右侧菜单
            configureMap.put(ProductConfigConstants.hasCameraVideo, true); //摄像头视频
            configureMap.put(ProductConfigConstants.hasWashMop, false);                 //是否可以自动清洗拖布
            configureMap.put(ProductConfigConstants.hasShare, true);//设备分享

            //机器人设置界面
            configureMap.put(ProductConfigConstants.voiceAssistant, true);//语音助手
            configureMap.put(ProductConfigConstants.robotSetting_multiMap, true);//是否有多地图开启开关
            configureMap.put(ProductConfigConstants.cleaning_mop_settings, true);//清洗拖布设置
            configureMap.put(ProductConfigConstants.cleaning_unit_area, true);//单位面积
            configureMap.put(ProductConfigConstants.child_lock, true);//童锁
            configureMap.put(ProductConfigConstants.cleanRecordHead, true);//清扫记录界面是否有上面那部分
            configureMap.put(ProductConfigConstants.dustSuction_time, false);//集尘吸力/集尘时长

            //机器人固件信息
            configureMap.put(ProductConfigConstants.hasBaseStationVersion, false);//基站版本号 只有zw有
            configureMap.put(ProductConfigConstants.hasUUID, true);//UUID
            configureMap.put(ProductConfigConstants.hasSN, false);//SN
            configureMap.put(ProductConfigConstants.robotInfo_wifi, true);//机器人信息 wifi
            configureMap.put(ProductConfigConstants.hostMac, false);//X5基站Mac地址
            configureMap.put(ProductConfigConstants.hostFirmwareVersion, false);//X5基站固件版本号
            configureMap.put(ProductConfigConstants.firmwareUpgradeWay, false);//N5 陀螺仪 固件更新方式
            JSONArray sp = new JSONArray();
            sp.put("樱花粉");
            sp.put("鸢尾蓝");
            sp.put("原子灰");
            configureMap.put(ProductConfigConstants.robotIconColorSpecies, sp);

            configureMap.put(ProductConfigConstants.automaticCleanTime, false);//自动集尘频率次数
            configureMap.put(ProductConfigConstants.rechargeBaseStation, true);//基站UI
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public static boolean canUpgradeFirmware() {
        //充电中、充电完成、 风干拖布中、清洗拖布中、注水中、集尘中都可以升级（这些状态都是在充电座上）
        Robot currentDevice = AppContext.get().getCurrentDevice();
        if (currentDevice != null) {
            int workState = AppContext.get().getCurrentDevice().getRobotStatus().getWorkState();
            int battery = AppContext.get().getCurrentDevice().getRobotStatus().getBattery();
            if (battery < 20 || (workState != RobotStatus.STATE_CHARGING
                    && workState != RobotStatus.STATE_DRYING_MOP
                    && workState != RobotStatus.STATE_CLEANING_MOP
                    && workState != RobotStatus.STATE_WATER_INJECTION
                    && workState != RobotStatus.STATE_DUST_COLLECTION)) {
                return false;
            }
        }
        return true;
    }

//    public static int getRobotAirview(String deviceId) {
//        SharedPreferences sp = MyApplication.get().getSharedPreferences("SP_ROBOT_ICON", Context.MODE_PRIVATE);
//        String peopleListJson = sp.getString("KEY_RobotIcon_LIST_DATA", "");
//        int iconId = R.mipmap.main_u3pro_icon;
//        if (peopleListJson != "")  //防空判断
//        {
//            Gson gson = new Gson();
//            List<RobotIconColorBean> mList = gson.fromJson(peopleListJson, new TypeToken<List<RobotIconColorBean>>() {
//            }.getType());
//            if (mList != null) {
//                LogUtils.i(" :  ===getRobotAirview=getRobotAirview ===========U3FULL " + mList.size());
//                for (int i = 0; i < mList.size(); i++) {
//                    LogUtils.i(mList.get(i).getDeviceId() + " :  ===getRobotAirview=getRobotAirview ===========U3FULL  " + deviceId);
//                    if (mList.get(i).getDeviceId().equals(deviceId)) {
//                        String color = mList.get(i).getIsICutoverColor();
//                        if (color != null) {
//                            if ("blue".equals(color)) {
//                                iconId = R.mipmap.main_u3pro_icon;
//                            } else if ("pink".equals(color)) {
//                                iconId = R.mipmap.main_u3pro_icon;
//                            } else if ("white".equals(color)) {
//                                iconId = R.mipmap.main_u3pro_icon;
//                            } else if ("gray".equals(color)) {
//                                iconId = R.mipmap.main_u3pro_icon;
//                            } else {
//                                iconId = R.mipmap.main_u3pro_icon;
//                            }
//                        }
//                        break;
//                    }
//                }
//            }
//        }
//        return iconId;
//    }
}
